var p = Object.defineProperty;
var d = (s, r, t) =>
  r in s
    ? p(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t })
    : (s[r] = t);
var a = (s, r, t) => (d(s, typeof r != 'symbol' ? r + '' : r, t), t);
import { createNode as h } from '../doc/createNode.js';
import { stringifyCollection as g } from '../stringify/stringifyCollection.js';
import { Collection as S } from './Collection.js';
import { SEQ as y, isScalar as l } from './identity.js';
import { isScalarValue as b } from './Scalar.js';
import { toJS as N } from './toJS.js';
class O extends S {
  constructor(t) {
    super(y, t);
    a(this, 'items', []);
  }
  static get tagName() {
    return 'tag:yaml.org,2002:seq';
  }
  add(t) {
    this.items.push(t);
  }
  /**
   * Removes a value from the collection.
   *
   * `key` must contain a representation of an integer for this to succeed.
   * It may be wrapped in a `Scalar`.
   *
   * @returns `true` if the item was found and removed.
   */
  delete(t) {
    const e = f(t);
    return typeof e != 'number' ? !1 : this.items.splice(e, 1).length > 0;
  }
  get(t, e) {
    const i = f(t);
    if (typeof i != 'number') return;
    const n = this.items[i];
    return !e && l(n) ? n.value : n;
  }
  /**
   * Checks if the collection includes a value with the key `key`.
   *
   * `key` must contain a representation of an integer for this to succeed.
   * It may be wrapped in a `Scalar`.
   */
  has(t) {
    const e = f(t);
    return typeof e == 'number' && e < this.items.length;
  }
  /**
   * Sets a value in this collection. For `!!set`, `value` needs to be a
   * boolean to add/remove the item from the set.
   *
   * If `key` does not contain a representation of an integer, this will throw.
   * It may be wrapped in a `Scalar`.
   */
  set(t, e) {
    const i = f(t);
    if (typeof i != 'number')
      throw new Error(`Expected a valid index, not ${t}.`);
    const n = this.items[i];
    l(n) && b(e) ? (n.value = e) : (this.items[i] = e);
  }
  toJSON(t, e) {
    const i = [];
    e != null && e.onCreate && e.onCreate(i);
    let n = 0;
    for (const o of this.items) i.push(N(o, String(n++), e));
    return i;
  }
  toString(t, e, i) {
    return t
      ? g(this, t, {
          blockItemPrefix: '- ',
          flowChars: { start: '[', end: ']' },
          itemIndent: (t.indent || '') + '  ',
          onChompKeep: i,
          onComment: e,
        })
      : JSON.stringify(this);
  }
  static from(t, e, i) {
    const { replacer: n } = i,
      o = new this(t);
    if (e && Symbol.iterator in Object(e)) {
      let u = 0;
      for (let m of e) {
        if (typeof n == 'function') {
          const c = e instanceof Set ? m : String(u++);
          m = n.call(e, c, m);
        }
        o.items.push(h(m, void 0, i));
      }
    }
    return o;
  }
}
function f(s) {
  let r = l(s) ? s.value : s;
  return (
    r && typeof r == 'string' && (r = Number(r)),
    typeof r == 'number' && Number.isInteger(r) && r >= 0 ? r : null
  );
}
export { O as YAMLSeq };
